home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / a86v400.zip / A04.DOC < prev    next >
Text File  |  1994-12-21  |  12KB  |  255 lines

  1. CHAPTER 4   ELEMENTS OF THE A86 LANGUAGE
  2.  
  3. This chapter begins the description of the A86 language.  It's a
  4. bit more tutorial in nature than the rest of the manual.  I'll
  5. start by describing the elementary building blocks of the
  6. language.
  7.  
  8.  
  9. General Categories of A86 Elements
  10.  
  11. The statements in an A86 source file can be classified in three
  12. general categories: instruction statements, data allocation
  13. statements, and assembler directives.  An instruction statement
  14. uses an easily remembered name (a mnemonic) and possibly one or
  15. more operands to specify a machine instruction to be generated.
  16. A data allocation statement reserves, and optionally initializes,
  17. memory space for program data.  An assembler directive is a
  18. statement that gives special instructions to the assembler.
  19. Directives are unlike the instruction and data allocation
  20. statements in that they do not specify the actual contents of
  21. memory.  Examples of the three types of A86 statements are given
  22. below.  These are provided to give you a general idea of what the
  23. different kinds of statements look like.
  24.  
  25. Instruction Statements
  26.  
  27. MOV AX,BX
  28. CALL SORT_PROCEDURE
  29. ADD AL,7
  30.  
  31. Data Allocation Statements
  32.  
  33. A_VARIABLE DW 0
  34. DB 'HELLO'
  35.  
  36. Assembler Directives
  37.  
  38. CODE SEGMENT
  39. ITEM_COUNT EQU 5
  40.  
  41. The statements in an A86 source file are made up of reserved
  42. symbols, user symbols, numbers, strings, special characters, and
  43. comments.
  44.  
  45. Symbols are the "words" of the A86 language.  All symbols are a
  46. collection of consecutive letters, numbers, and assorted special
  47. characters: _, @, $, and ?.  Symbols cannot begin with digits:
  48. anything that begins with a digit is a number.  Symbols can begin
  49. with any of the special characters just listed.  Symbols can also
  50. begin with a period, which is the only place within the symbol
  51. name a period can appear.
  52.                                                               4-2
  53.  
  54. Reserved symbols have a built-in meaning to the assembler:
  55. instruction mnemonics (MOV, CALL), directive names (DB, STRUC),
  56. register names, expression operators, etc.  User symbols have
  57. meanings defined by the programmer: program locations, variable
  58. names, equated constants, etc.  The user symbol name is
  59. considered unique up to 127 characters, but it can be of any
  60. length (up to 255 characters).   Examples of user symbols are:
  61. COUNT, L1, and A_BYTE.
  62.  
  63. Numbers in A86 may be expressed as decimal, hexadecimal, octal,
  64. binary, or decimal "K".  These must begin with a decimal digit
  65. and, except in the case of a decimal or hexadecimal number, must
  66. end with "x" followed by a letter identifying the base of the
  67. number.  A number without an identifying base is hexadecimal if
  68. the first digit is 0; decimal if the first digit is 1 through 9.
  69. Examples of A86 numbers are: 123 (decimal), 0ABC (hexadecimal),
  70. 1776xQ (octal), 10100110xB (binary), and 32K (decimal 32 times
  71. 1024).
  72.  
  73. Strings are characters enclosed in either single or double
  74. quotes.  Examples of strings are: '1st string' and "SIGN-ON
  75. MESSAGE, V1.0".  If you wish to include a quote mark within a
  76. string, you can double it; for example, 'that''s nice' specifies
  77. a single quote mark within the string.  The single quote and
  78. double quote are two of many special characters used in the
  79. assembly language.  Others, run together in a list, are: ! $ ? ;
  80. : = , [ ] . + - ( ) * / >.  The space and tab characters are also
  81. special characters, used as separators in the assembly language.
  82.  
  83. A comment is a sequence of characters used for program
  84. documentation only; it is ignored by the assembler.  Comments
  85. begin with a semicolon (;) and run to the end of the line on
  86. which they are started.  Examples of lines with comments are
  87. shown below:
  88.  
  89. ; This entire line is a comment.
  90. MOV AX,BX  ; This is a comment next to an instruction statement.
  91.  
  92. Alternatively, for compatibility with other assemblers, I provide
  93. the COMMENT directive.  The next non-blank character after
  94. COMMENT is a delimiter to a comment that can run across many
  95. lines; all text is ignored, until a second instance of the
  96. delimiter is seen.  For example,
  97.  
  98. COMMENT 'This comment
  99. runs across two lines'
  100.  
  101. I don't like COMMENT, because I think it's very dangerous.  If,
  102. for example, you have two COMMENTs in your program, and you
  103. forget to close the first one, the assembler will happily ignore
  104. all source code between the comments.  If that source code does
  105. not happen to contain any labels referenced elsewhere, the error
  106. may not be detected until your program blows up.  For multiline
  107. comments, I urge you to simply start each line with a semicolon.
  108.                                                               4-3
  109.  
  110. Statements in the A86 are line oriented, which means that
  111. statements may not be broken across line boundaries.  A86 source
  112. lines may be entered in a free form fashion; that is, without
  113. regard to the column orientation of the symbols and special
  114. characters.
  115.  
  116. PLEASE NOTE: Because an A86 line is free formatted, there is no
  117. need for you to put the operands to your instructions in a
  118. separate column.  You organize things into columns when you want
  119. to visually scan down the column; and you practically never scan
  120. operands separate from their opcodes.  Realizing this, you may
  121. wish to separate your operands from the mnemonic with a space
  122. instead of a tab, making the line less disjointed and hence
  123. easier to read.  You will also have room for a longer comment
  124. after the instruction.
  125.  
  126.  
  127. Operand Typing and Code Generation
  128.  
  129. A86 is a strongly typed assembly language.   What this means is
  130. that operands to instructions (registers, variables, labels,
  131. constants) have a type attribute associated with them which tells
  132. the assembler something about them.  For example, the operand 4
  133. has type "number", which tells the assembler that it is a
  134. numerical constant, rather than a register or an address in the
  135. code or data.  The following discussion explains the types
  136. associated with instruction operands and how this type
  137. information is used to generate particular machine opcodes from
  138. general purpose instruction mnemonics.
  139.  
  140. Registers
  141.  
  142. The 8086 has 8 general purpose word (two-byte) registers:
  143. AX,BX,CX,DX,SI,DI,BP, and SP.  The first four of those registers
  144. are subdivided into 8 general purpose one-byte registers
  145. AH,AL,BH,BL,CH,CL,DH, and DL.  There are also 4 16-bit segment
  146. registers CS,DS,ES, and SS, used for addressing memory; and the
  147. implicit instruction-pointer register (referred to as IP,
  148. although "IP" is not part of the A86 assembly language).
  149.  
  150. My A386 assembler supports the two additional segment registers
  151. FS and GS, plus the 32-bit general registers
  152. EAX,EBX,ECX,EDX,ESI,EDI,EBP, and ESP.  The lower 16 bits of each
  153. 32-bit register is the corresponding 16-bit register (without the
  154. E in its name).
  155.  
  156. Variables
  157.  
  158. A variable is a unit of program data with a symbolic name,
  159. residing at a specific location in 8086 memory.  A variable is
  160. given a type at the time it is defined, which indicates the
  161. number of bytes associated with its symbol.  Variables defined
  162. with a DB statement are given type BYTE (one byte), and those
  163. defined with the DW statement are given type WORD (two bytes).
  164. Examples:
  165.                                                               4-4
  166.  
  167. BYTE_VAR DB 0   ; A byte variable.
  168. WORD_VAR DW 0   ; A word variable.
  169.  
  170. Labels
  171.  
  172. A label is a symbol referring to a location in the program code.
  173. It is defined as an identifier, followed by a colon (:), used to
  174. represent the location of a particular instruction or data
  175. structure.  Such a label may be on a line by itself or it may
  176. immediately precede an instruction statement (on the same line).
  177. In the following example, LABEL_1 and LABEL_2 are both labels for
  178. the MOV AL,BL instruction.
  179.  
  180. LABEL_1:
  181. LABEL_2: MOV AL,BL
  182.  
  183. In the A86 assembly language, labels have a type identical to
  184. that of constants.  Thus, the instruction MOV BX,LABEL_2 is
  185. accepted, and the code to move the immediate constant address of
  186. LABEL2 into BX, is generated.
  187.  
  188. IMPORTANT: you must understand the distinction between a label
  189. and a variable, because you may generate a different